package com.wry.wry_test.config;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @Author: wangrongyi
 * @Date: 2024/9/30 11:13
 * @Description:
 */
@Component
public class ApplicationInitConfig implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("应用启动完成，正在执行初始化任务...");

        // 获取非选项参数
        String[] nonOptionArgs = args.getNonOptionArgs().toArray(new String[0]);
        for (String arg : nonOptionArgs) {
            System.out.println("非选项参数: " + arg);
        }

        // 获取选项参数
        String[] optionNames = args.getOptionNames().toArray(new String[0]);
        for (String optionName : optionNames) {
            System.out.println("选项名称: " + optionName);
            if (args.containsOption(optionName)) {
                System.out.println("包含选项: " + optionName);
                String[] optionValues = args.getOptionValues(optionName).toArray(new String[0]);
                for (String value : optionValues) {
                    System.out.println("选项值: " + value);
                }
            }
        }
    }
}
